#include <bits/stdc++.h>
using namespace std;
#define ll long long

int jjpow(int, int);
int jjC(ll, ll);

const int N = 100010, MOD = 1e9 + 7;

int n, i1 , i2, i3, i4, i5;
vector<int>a1(N), a2(N), a3(N), a4(N), a5(N);

void solve(){
    
}

void init(){
    i1 = i2 = i3 = i4 = i5 =0;
    scanf("%d", &n);    
    int tmp;
    for(int i = 0; i < n; ++i){
        scanf("%d", &tmp);
        if(tmp == 1){
            a1[i1] = i + 1;
            ++i1;
        }else if(tmp == 2){
            a2[i2] = i + 1;
            ++i2;
        }else if(tmp == 3){
            a3[i3] = i + 1;
            ++i3;
        }else if(tmp == 4){
            a4[i4] = i + 1;
            ++i4;
        }else{
            a5[i5] = i + 1;
            ++i5;
        }
        if(i1 && i2 && i3 && i4 && i5){
            printf("%d %d %d %d %d\n", a1[i1 - 1], a2[i2 - 1], a3[i3 - 1], a4[i4 - 1], a5[i5 - 1]);
            --i1;--i2;--i3;--i4;--i5;
        }else{
            printf("-1\n");
        }
    }
}

int main(){
    #ifndef ONLINE_JUDGE
        auto start_clock = clock();
        //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    #endif
    
    init();
    solve();
    
    #ifndef ONLINE_JUDGE
        auto end_clock = clock();
        //cout<<"runtime: "<<end_clock - start_clock<<"ms"<<endl;
    #endif
    return 0;
}

int jjpow(int a, int b){
    if(b == 2)return (a * a)%MOD;
    if(b == 1)return a;
    int ret1 = a, ret2 = a;
    int cnt1 = log(b)/log(2);
    int cnt2 = b - pow(2, cnt1);
    ret1 = jjpow(a, cnt2);
    for(int i = 0; i < cnt1; ++i){
        ret2 = (ret2 * ret2)%MOD;
    }
    return (ret1 * ret2)%MOD;
}

int jjC(ll a, ll b){
    int ret = 1, tmp = 1;
    for(int i = a; i > a - b; --i){
        ret = (ret * i)%MOD;
    }
    for(int i = 2; i <= b; ++i){
        tmp = (tmp * i)%MOD;
    }
    printf("%d %d\n", ret, tmp);
    return ret/tmp;
}
